﻿
@{
    Layout = "~/Views/Shared/_AddEdit.cshtml";
}

@section header{
<script type="text/javascript">
        function SaveBeforeCallBack() {
            if ($("#_FlowingType").val() == '') {
                layer.msg('温馨提示：必须选择流水类型~！~'); return true;
            }
            if ($("#_FlowingType").val().substring(3, 5) == "01" && $("#_cid").val() == '') {
                layer.msg('温馨提示：选择客户类流水类型时必须填写客户信息~！~'); return true;
            }
            if ($("#_FlowingType").val().substring(3, 5) == "02" && $("#_activityId").val() == '') {
                layer.msg('温馨提示：选择活动类流水类型时必须填写活动信息~！~'); return true;
            }
            if ($("#_Account").val() == '') {
                layer.msg('温馨提示：必须输入金额~！~'); return true;
            }
            if ($("#_AccountMode").val() == '') {
                layer.msg('温馨提示：必须选择资金来源~！~'); return true;
            }
            var je = parseFloat($("#_Account").val());
            var fje = -je;
           
            if($("input[name='_AccountType']:checked").val() != "收入类" && je > 0)
            $("#_Account").val(fje);
            if (@ViewBag.data["state"]> 0 && @ViewBag.Lx == 1) { layer.msg("已入帐不可修改!"); return true; }
           
            $("#_CreateDate").val("@System.DateTime.Now");


        }




    </script>
}

<input type="hidden" name="_LeagueId" id="_LeagueId" value="@ViewBag.data["LeagueId"]" />
<input type="hidden" name="_state" id="_state" value="@ViewBag.data["state"]" />
<input type="hidden" name="_CreateId" id="_CreateId" value="@ViewBag.data["CreateId"]" />
<input type="hidden" name="_ContractId" id="_ContractId" value="@ViewBag.data["ContractId"]" />
<input type="hidden" name="_AchievementId" id="_AchievementId" value="@ViewBag.data["AchievementId"]" />
<input type="hidden" name="_CreateDate" id="_CreateDate" value="@ViewBag.data["CreateDate"]" />
<input type="hidden" name="_cid" id="_cid" value="@ViewBag.data["cid"]" />
<input type="hidden" name="_activityId" id="_activityId" value="@ViewBag.data["activityId"]" />
<div style=" margin-top:20px;"></div>

    <div class="layui-col-md12">
        <div class="layui-card">
            <div class="layui-form-item">
                <label class="layui-form-label">帐目类型</label>
                <div class="layui-input-block">

                    <input type="radio" name="_AccountType" lay-filter="AccountType" value="收入类" title="收入类" @(ViewBag.data["AccountType"] == "收入类" ? "checked='checked'" : "")>
                    <input type="radio" name="_AccountType" lay-filter="AccountType" value="支出类" title="支出类" @(ViewBag.data["AccountType"] == "支出类" ? "checked='checked'" : "")>
                    <input type="radio" name="_AccountType" lay-filter="AccountType" value="预算" title="预算" @(ViewBag.data["AccountType"] == "预算" ? "checked='checked'" : "")>
                </div>
            </div>
            <div class="layui-form-item">

                <label class="layui-form-label" id="lxxz">流水类型</label>
                <div class="layui-input-inline">
                    <select lay-verify="required" name="_FlowingType" lay-filter="FlowingType" id="_FlowingType">
                        <option value=""></option>
                        @foreach (var data in ViewBag.FlowingType.Rows)
                        {

                            <option value="@data["did"]" @(ViewBag.data["FlowingType"] == @data["did"] ? "selected" : "")>@data["dname"]</option>
                        }

                    </select>

                </div>

            </div>
            <div class="layui-form-item" id="xyxx" style="display:none;">
                <label class="layui-form-label">选择客户</label>
                <div class="layui-input-inline">
                    <input type="text" id="CusDisplay" placeholder="请输入手机号码进行查询" class="layui-input">
                </div><a class="layui-btn" href="#" onclick="searchCus()"><i class="layui-icon">&#xe615;</i></a> <div id="xy"> @ViewBag.CustMessage</div>
            </div>
            <div class="layui-form-item" id="xyselect" style="display:none;">
                <table class="layui-table" lay-skin="line" lay-filter="demo" id="demo"></table>
            </div>
            <div class="layui-form-item" id="Htxx" style="display:none;">
                <label class="layui-form-label">选择合同</label>
                <div class="layui-input-inline">
                    <input type="text" id="HtDisplay" placeholder="请输入合同编码进行查询" class="layui-input">
                </div><a class="layui-btn" href="#" onclick="searchHt()"><i class="layui-icon">&#xe615;</i></a>  <div id="Ht">@ViewBag.CustMessage</div>
            </div>
            <div class="layui-form-item" id="Htselect" style="display:none;">
                <table class="layui-table" lay-skin="line" lay-filter="httable" id="httable"></table>
            </div>

            <div class="layui-form-item" id="hdxx" style="display:none;">
                <label class="layui-form-label">选择活动</label>
                <div class="layui-input-inline">
                    <input type="text" id="HdDisplay" placeholder="请输入活动名称进行查询" class="layui-input">
                </div><a class="layui-btn" href="#" onclick="searchHd()"><i class="layui-icon">&#xe615;</i></a><div id="Hd">@ViewBag.CustMessage </div>
            </div>
            <div class="layui-form-item" id="Hdselect" style="display:none;">
                <table class="layui-table" lay-skin="line" lay-filter="hdtable" id="hdtable"></table>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">日期</label>
                <div class="layui-input-inline">
                    <input type="text" name="_ADate" id="BirdDate" value="@ViewBag.data["ADate"]" required lay-verify="required" placeholder="请选择支出日期" lay-verType="tips" autocomplete="off" class="layui-input">
                </div>


            </div>
            <div class="layui-form-item">
                <label class="layui-form-label" id="je">金额</label>
                <div class="layui-input-inline">
                    <input type="text" name="_Account" id="_Account" value="@ViewBag.data["Account"]" required lay-verify="number" placeholder="请输入支出金额" lay-verType="tips" autocomplete="off" class="layui-input">
                </div>


            </div>
            <div class="layui-form-item">

                <label class="layui-form-label" id="zjly">资金来源 </label>
                <div class="layui-input-inline">
                    <select name="_AccountMode" id="_AccountMode" lay-verify="required">
                        <option value=""></option>
                        @foreach (var data in ViewBag.AccountMode.Rows)
                        {

                            <option value="@data["did"]" @(ViewBag.data["AccountMode"] == @data["did"] ? "selected" : "")>@data["dname"]</option>
                        }
                    </select>
                </div>
            </div>
            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">备注信息</label>
                <div class="layui-input-block">
                    <textarea name="_Remark" placeholder="请输入内容" class="layui-textarea" style="min-height:100px;min-width:300px;">@ViewBag.data["Remark"]</textarea>
                </div>
            </div>


        </div>
    </div>


<script src="../Layui/layui.js"></script>

<script>
    layui.config({
        base: '../Layui/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use('index');
</script>

<script>
    layui.use('laydate', function () {
        var laydate = layui.laydate;

        //执行一个laydate实例
        laydate.render({
            elem: '#BirdDate' //指定元素
            , value: new Date()
        });


    });
</script>
<script>
    layui.use('form', function () {
        var form = layui.form;

        //各种基于事件的操作，下面会有进一步介绍

        form.on('radio(AccountType)', function (data) {

            if (data.value == "收入类") $("#_state").val("2");
            else
                $("#_state").val("0");
            $.ajax({
                url: "../Account/At/FlowingTypeData",
                dataType: "json",
                data: {
                    type: "@ViewBag.type",
                    id: "@ViewBag.id",
                    keyCode: data.value,
                    t: new Date().getTime()
                },
                success: function (data) {

                    if (data.code = "0000") {
                        $('#_FlowingType').html("");
                        var t = '<option value="">请选择类型</option>';
                        for (var i = 0; i < data.data.length; i++) {
                            t += ' <option value="' + data.data[i].did + '" >' + data.data[i].dname + '</option > ';
                        }
                        $('#_FlowingType').append(t);
                        form.render('select');
                    }
                }


            });

        });

        form.on('select(FlowingType)', function (data) {

            $("#_AchievementId").val('');
            $("#_cid").val('');
            $("#_ContractId").val('');
            $("#_activityId").val('');

            if (data.value.substring(3, 5) == "01") {
                $("#xyxx").css('display', '');

                $("#Htxx").css('display', 'none');
                $("#htselect").css('display', 'none');              
                $("#Ht").val('');
               
                $("#hdxx").css('display', 'none');
                $("#Hdselect").css('display', 'none');              
                $("#Hd").val('');
            }
            else if (data.value.substring(3, 5) == "03") {
                $("#hdxx").css('display', '');

                $("#xyxx").css('display', 'none');
                $("#xyselect").css('display', 'none');               
                $("#xy").val('');

                $("#Htxx").css('display', 'none');
                $("#htselect").css('display', 'none');            
                $("#Ht").val('');
            }
            else if (data.value.substring(3, 5) == "02") {
                $("#Htxx").css('display', '');

                $("#xyxx").css('display', 'none');
                $("#xyselect").css('display', 'none');
                $("#xy").val('');

                $("#hdxx").css('display', 'none');
                $("#Hdselect").css('display', 'none');
                $("#Hd").val('');

            }
            else {
                $("#xyxx").css('display', 'none');
                $("#xyselect").css('display', 'none');
                $("#xy").val('');

                $("#hdxx").css('display', 'none');
                $("#Hdselect").css('display', 'none');
                $("#Hd").val('');

                $("#Htxx").css('display', 'none');
                $("#htselect").css('display', 'none');
                $("#Ht").val('');
            } //复选框value值，也可以通过data.elem.value得到


        });
    })
</script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
     function searchHt() {

            $.ajax({
                url: "../Account/At/HtData",
        dataType:"json",
        data: {
            type:"@ViewBag.type",
            id:"@ViewBag.id",
            keyCode:$("#HtDisplay").val(),
            t:new Date().getTime()
        },
        success: function( data ) {

            if (data.code = "0000") {
                var json = eval(data.data); //数组
                if (json.length == 1) {
                    
                    $("#Ht").html("<div class= \"layui-col-md12 layui-col-xs12\" style=\"margin-left: 50px;height:50px; line-height:50px;\">合同信息:<span class=\"layui-badge\">" + data.data[0].contractNumber +"</span>" +data.data[0].SetmealName+ "　应收:" + data.data[0].ContractPrice + "　实收:<span class=\"layui-badge layui-bg-orange\">" + data.data[0].DisPrice + "</span>　宝宝:" + data.data[0].CustName + "　联系人:" + data.data[0].LinkName + "<br></div>");
                    $("#_cid").val(json[0].cid);
                    $("#_AchievementId").val(json[0].LatelyReceId);
                    $("#_ContractId").val(json[0].id);
                    $("#Htselect").css('display', 'none');
                }
                else if (json.length > 1) {
                    $("#Htselect").css('display', '');
                    layui.use('layer', function () {
                        var layer = layui.layer;
                        layer.open({
                            title: '请选择合同信息',
                            type: 1,
                            shadeClose: true,
                            area: ['700px', '500px'],
                            content: $("#Htselect").html("<table class=\"layui - table\" lay-skin=\"line\" lay-filter=\"httable\" id=\"httable\"></table>")

                        });
                    })
                    layui.use('table', function () {
                     var table = layui.table;
                    table.render({
                        elem: '#demo'
                        , cols: [[ //标题栏
                            { field: 'id', title: 'ID', width: 60, sort: true }
                            , { field: 'contractNumber', title: '编号', width: 100 }
                            , { field: 'SetmealName', title: '套餐', width: 100 }
                            , { field: 'ContractPrice', title: '应收', Width: 80 }
                            , { field: 'DisPrice', title: '实收', Width: 80 }
                            , { field: 'CustName', title: '宝宝姓名', minwidth: 100 }
                            , { field: 'LinkName', title: '联系人', width: 80 }
                        ]]
                        , data: data.data
                       ,skin: 'line' //表格风格
                        , even: true
                        ,page: true //是否显示分页

                        , limit: 5 //每页默认显示的数量

                        });
                        table.on('row(demo)', function (obj) {

                            var data = obj.data;
                            $("#Ht").html("<div class= \"layui-col-md12 layui-col-xs12\" style=\"margin-left: 50px;height:50px; line-height:50px;\">合同信息:<span class=\"layui-badge\">" + data.contractNumber +"</span>"+ data.SetmealName + "　应收:" + data.ContractPrice + "　实收:<span class=\"layui-badge layui-bg-orange\">" + data.DisPrice + "</span>　宝宝:" + data.CustName + " 　联系人:" + data.LinkName + "<br></div>");

                            $("#_cid").val(data.cid);
                            $("#_AchievementId").val(data.LatelyReceId);
                            $("#_ContractId").val(data.id);
                            layer.closeAll('page');
                            $("#Htselect").html('');
                        });

                    });
                }
                else {
                    $("#xy").html("未找到学员信息");
                    $("#_cid").val("");
                    $("#_AchievementId").val("");
                    $("#_ContractId").val("");
                    $("#Htselect").css('display', 'none');
                }

            }

        }
    });
    }
    function searchCus() {

            $.ajax({
        url: "../Account/At/Data",
        dataType:"json",
        data: {
            type:"@ViewBag.type",
            id:"@ViewBag.id",
            keyCode:$("#CusDisplay").val(),
            t:new Date().getTime()
        },
        success: function( data ) {

            if (data.code = "0000") {
                var json = eval(data.data); //数组
                if (json.length == 1) {
                    if (json[0].Sex.replace(/^\s+|\s+$/g, "") == "男")
                        $("#xy").html("<div class= \"layui-col-md12 layui-col-xs12\" style=\"margin-left: 50px;height:50px; line-height:50px;\">学员信息:<i class=\"layui-icon layui-icon-male layui-bg-blue\"></i>" + data.data[0].CustName + "　宝宝小名:" + data.data[0].ChildName + "　Tel:<span class=\"layui-badge layui-bg-orange\">" + data.data[0].CustTel + "</span>　订金:<span class=\"layui-badge\">" + data.data[0].je + "</span>　业绩所属:<span class=\"layui-badge layui-bg-green \">" + data.data[0].AchievementName + "</span>　联系人:" + data.data[0].LinkName +  "<br></div>");
                    else
                        $("#xy").html("<div class= \"layui-col-md12 layui-col-xs12\" style=\"margin-left: 50px;height:50px; line-height:50px;\">学员信息:<i class=\"layui-icon  layui-icon-female layui-bg-blue\"></i>" + data.data[0].CustName + "　宝宝小名:" + data.data[0].ChildName + "　Tel:<span class=\"layui-badge layui-bg-orange\">" + data.data[0].CustTel + "</span>　订金:<span class=\"layui-badge\">" + data.data[0].je + "</span>　业绩所属:<span class=\"layui-badge layui-bg-green \">" + data.data[0].AchievementName + "</span>　联系人:" + data.data[0].LinkName + "<br></div>");
                    $("#_cid").val(json[0].id);
                    $("#_AchievementId").val(json[0].LatelyReceId);
                    $("#xyselect").css('display', 'none');
                }
                else if (json.length > 1) {
                    $("#xyselect").css('display', '');
                    layui.use('layer', function () {
                        var layer = layui.layer;
                        layer.open({
                            title: '请选择订金人员信息',
                            type: 1,
                            shadeClose: true,
                            area: ['700px', '500px'],
                            content: $("#xyselect").html("<table class=\"layui - table\" lay-skin=\"line\" lay-filter=\"demo\" id=\"demo\"></table>")

                        });
                    })
                    layui.use('table', function () {
                     var table = layui.table;
                    table.render({
                        elem: '#demo'
                        , cols: [[ //标题栏
                            { field: 'id', title: 'ID', width: 60, sort: true }
                            , { field: 'CustName', title: '宝宝姓名', width: 100 }
                            , { field: 'ChildName', title: '小名', Width: 80 }
                            , { field: 'LinkName', title: '联系人', Width: 80 }
                            , { field: 'CustTel', title: '联系电话', minwidth: 100 }
                            , { field: 'LinkRelation', title: '关系', width: 80 }
                        ]]
                        , data: data.data
                       ,skin: 'line' //表格风格
                        , even: true
                        ,page: true //是否显示分页

                        , limit: 5 //每页默认显示的数量

                        });
                        table.on('row(demo)', function (obj) {

                            var data = obj.data;
                            if (data.Sex.replace(/^\s+|\s+$/g, "") == "男")
                                $("#xy").html("<div class= \"layui-col-md12 layui-col-xs12\" style=\"margin-left: 50px;height:50px; line-height:50px;\">学员信息:<i class=\"layui-icon layui-icon-male layui-bg-blue\"></i>" + data.CustName + "　宝宝小名:" + data.ChildName + "　Tel:<span class=\"layui-badge layui-bg-orange\">" + data.CustTel + "</span>　订金:<span class=\"layui-badge\">" + data.je + "</span>　业绩所属:<span class=\"layui-badge layui-bg-green \">" + data.AchievementName + "</span>　联系人:" + data.LinkName + "<br></div>");

                            else
                                $("#xy").html("<div class= \"layui-col-md12 layui-col-xs12\" style=\"margin-left: 50px;height:50px; line-height:50px;\">学员信息:<i class=\"layui-icon layui-icon-female layui-bg-blue\"></i>" + data.CustName + "　宝宝小名:" + data.ChildName + "　Tel:<span class=\"layui-badge layui-bg-orange\">" + data.CustTel + "</span>　订金:<span class=\"layui-badge\">" + data.je + "</span>　业绩所属:<span class=\"layui-badge layui-bg-green \">" + data.AchievementName + "</span>　联系人:" + data.LinkName + "<br></div>");


                            $("#_cid").val(data.id);
                            $("#_AchievementId").val(data.LatelyReceId);
                            layer.closeAll('page');
                            $("#xyselect").html('');
                        });

                    });
                }
                else {
                    $("#xy").html("未找到学员信息");
                    $("#_cid").val("");
                    $("#_AchievementId").val("");
                    $("#xyselect").css('display', 'none');
                }

            }

        }
    });
    }
    function searchHd() {

            $.ajax({
        url: "../Account/At/HdData",
        dataType:"json",
        data: {
            type:"@ViewBag.type",
            id:"@ViewBag.id",
            keyCode:$("#HdDisplay").val(),
            t:new Date().getTime()
        },
        success: function( data )
        {

            if (data.code = "0000") {
                var json = eval(data.data); //数组
                if (json.length == 1) {
                    $("#Hd").html("活动名称:" + json[0].ActivityName +"  电话：" + json[0].tel + "  价格:" + json[0].MPrice + "[" + json[0].NoMPrice + "]");
                    $("#_activityId").val(json[0].id);
                    $("#Hdselect").css('display', 'none');
                }
                else if (json.length > 1) {
                    $("#Hdselect").css('display', '');
                    $("#Hd").html("请选择活动信息");
                    layui.use('table', function () {
                     var table = layui.table;
                    table.render({
                        elem: '#hdtable'
                        , cols: [[ //标题栏
                            { field: 'id', title: 'ID', width: 60, sort: true }
                            , { field: 'ActivityName', title: '活动名称', width: 100 }
                            , { field: 'ActAddress', title: '活动地址', Width: 80 }
                            , { field: 'MPrice', title: '会员价', Width: 80 }
                            , { field: 'tel', title: '联系电话', minwidth: 100 }
                            , { field: 'Classhour', title: '抵课时', width: 80 }
                            , { field: 'NoMPrice', title: '非会员价', width: 80 }
                        ]]
                        , data: data.data
                       ,skin: 'line' //表格风格
                        , even: true
                        ,page: true //是否显示分页

                        , limit: 5 //每页默认显示的数量

                        });
                        table.on('row(hdtable)', function (obj) {

                            var data = obj.data;
                            $("#Hd").html("活动名称:" + data.ActivityName + "  电话：" + data.tel + "  价格:" + data.MPrice + "[" + data.NoMPrice + "]");
                            $("#_activityId").val(data.id);
                            $("#Hdselect").css('display', 'none');
                        });

                    });
                }
                else {
                    $("#Hd").html("未找到活动信息");
                    $("#_activityId").val("");
                    $("#Hdselect").css('display', 'none');
                }

            }

        }
    });
    }
</script>
